package xyz.labmem.base.core.tool

import cn.hutool.core.util.ObjectUtil
import org.aspectj.lang.JoinPoint
import org.springframework.web.multipart.MultipartFile
import javax.servlet.http.HttpServletRequest
import javax.servlet.http.HttpServletResponse

/**
 * @Author lty
 * @Date 2021/12/16 14:06
 */

/**
 * 获取切面的参数json
 */
fun JoinPoint.getArgsToJsonStr(): String {
    /**
     * 判断是否需要拼接参数，过滤掉HttpServletRequest,MultipartFile,HttpServletResponse等类型参数
     */
    fun isFilterObject(arg: Any): Boolean =
        arg is MultipartFile || arg is HttpServletRequest || arg is HttpServletResponse

    val argsJson = StringBuilder()
    val args = this.args
    for (arg in args) {
        if (!isFilterObject(arg)) {
            if (ObjectUtil.isNotNull(arg)) {
                val jsonStr = arg.toJsonStr()
                argsJson.append(jsonStr).append(" ")
            }
        }
    }
    return argsJson.toString().trim { it <= ' ' }
}
